package org.example.model;

import java.util.List;
import java.util.Map;
//判断jsonpath的返回对象的类型
public class gettype {
    public static String gettype(Object obj){
        if(obj instanceof String) {
            System.out.println("Object is a string.");
            return "string";
        }
        if(obj instanceof Double){
            System.out.println("Object is a double");
            return "double";
        }

        // 判断是否为列表类型
        if(obj instanceof List) {
            List<?> list = (List<?>) obj;
            boolean isListString = list.stream().allMatch(element -> element instanceof String);
            boolean islistmap = list.stream().allMatch(element ->element instanceof Map);
            boolean isint = list.stream().allMatch(element ->element instanceof Integer);
            boolean isdouble = list.stream().allMatch(element ->element instanceof Double);


            if(isListString) {
                System.out.println("Object is a liststring.");
                return "liststring";
                //是List<String>
            }
            if(islistmap){
                System.out.println("Object is a listmap");
                return "listmap";
                //是List<Map<String,String>>
            }
            if(isdouble){
                System.out.println("Object is a listdouble");
                return "listdouble";
                //是List<Double>
            }
            if(isint){
                System.out.println("Object is a listint");
                return "listint";
                //是List<Integer>
            }

        }

        else {
            System.out.println("Not regular");
        }
        return  "no";
    }
}
